package com.wood_sheep.Controller;
/*
控制器层：接受view的请求，并转发给Model处理
 */

import com.wood_sheep.Model.Dao.LoginDao;
import com.wood_sheep.Model.Entity.Login;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //处理登录
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("uname");
        String pwd = request.getParameter("upwd");
        Login login = new Login(name, pwd);//用户名与密码

        //调用模型层的登录功能
        int result = LoginDao.login(login);

        if (result > 0) {//成功
            response.sendRedirect("welcome.jsp");
        } else {
            response.sendRedirect("login.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
